﻿// <copyright file="MapInfoFileTest.cs" company="QUT">
//     Copyright (c) Ninety Nine Percent. All rights reserved.
// </copyright>

using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using NUnit.Framework;

namespace Qut.GenerateKml.Data
{
    /// <summary>
    /// a class for testing MapInfoRegion class.
    /// </summary>
    [TestFixture]

    public class MapInfoFileTest
    {
        /// <summary>
        /// MapInfoFile MIF which is geographical data
        /// </summary>
        private MapInfoFile mif;

        /// <summary>
        /// MapInfoFile MIF which is geographical data
        /// </summary>
        private MapInfoFile mif2;

        /// <summary>
        /// the path of mif file
        /// </summary>
        private string mifFilePath;

        /// <summary>
        /// the path of mid file
        /// </summary>
        private string midFilePath;

        /// <summary>
        /// a List of MapInfoRegion type is used for test ReadMifData() and getMidData() functions
        /// </summary>  
        private List<MapInfoRegion> mifData;

        /// <summary>
        /// test the exception handling when initializing a MapInfoFile
        /// </summary>
        [Test]
        [ExpectedException(typeof(FileNotFoundException))]
        public void MapInfoFileExceptionTest1()
        {
            this.mifFilePath = "QLD.mif";
            this.midFilePath = "QLD_Federal_Electoral_Boundaries.MID";
            this.mif = new MapInfoFile(this.mifFilePath, this.midFilePath);
        }

        /// <summary>
        /// test the exception handling when initializing a MapInfoFile
        /// </summary>
        [Test]
        [ExpectedException(typeof(FileNotFoundException))]
        public void MapInfoFileExceptionTest2()
        {
            this.mifFilePath = "QLD_Federal_Electoral_Boundaries.mif";
            this.midFilePath = "Electoral_Boundaries.MID";
            this.mif = new MapInfoFile(this.mifFilePath, this.midFilePath);
        }

        /// <summary>
        /// Initializes the all data member in the test.
        /// </summary>
        [SetUp]
        public void Initialize()
        {
            this.mifFilePath = "Sample.mif";
            this.midFilePath = "Sample.MID";
            this.mif2 = new MapInfoFile(this.mifFilePath, this.midFilePath);
            this.mifData = new List<MapInfoRegion>();
        }

        /// <summary>
        /// test the private ReadMifData() and public getMidData() functions 
        /// </summary>
        [Test]
        public void MifDataTest() 
        {
            MapInfoPolygon mip = new MapInfoPolygon();
            PointF p1 = new PointF();
            p1.X = float.Parse("152.836397");
            p1.Y = float.Parse("-27.579269");
            PointF p2 = new PointF();
            p2.X = float.Parse("152.835951");
            p2.Y = float.Parse("-27.579239");
            PointF p3 = new PointF();
            p3.X = float.Parse("152.836397");
            p3.Y = float.Parse("-27.579269");
            mip.AddPoint(p1);
            mip.AddPoint(p2);
            mip.AddPoint(p3);
            MapInfoRegion mir = new MapInfoRegion();
            mir.AddPolygon(mip);
            this.mifData.Add(mir);
            Assert.AreEqual(this.mif2.GetMifData()[0].GetPolygons()[0].GetCoordinates()[0], this.mifData[0].GetPolygons()[0].GetCoordinates()[0]);
            Assert.AreEqual(this.mif2.GetMifData()[0].GetPolygons()[0].GetCoordinates()[1], this.mifData[0].GetPolygons()[0].GetCoordinates()[1]);
            Assert.AreEqual(this.mif2.GetMifData()[0].GetPolygons()[0].GetCoordinates()[2], this.mifData[0].GetPolygons()[0].GetCoordinates()[2]);
        }

        /// <summary>
        /// test the private public getMifHeader() and private readMifHeader() functions 
        /// </summary>
        [Test]
        public void MifHeaderTest1()
        {
            string coordValue = (string)this.mif2.GetMifHeader()["coordsys"];
            Assert.AreEqual(coordValue, "Earth Projection 1, 33");
        }

        /// <summary>
        /// test the private public getMifHeader() and private readMifHeader() functions 
        /// </summary>
        [Test]
        public void MifHeaderTest2()
        {
            string indexValue = (string)this.mif2.GetMifHeader()["index"];
            Assert.AreEqual(indexValue, "2");
        }

        /// <summary>
        /// test the private public getMifHeader() and private readMifHeader() functions 
        /// </summary>
        [Test]
        public void MifHeaderTest3()
        {
            string indexValue = (string)this.mif2.GetMifHeader()["charset"];
            Assert.AreEqual(indexValue, "WindowsLatin1");
        }

        /// <summary>
        /// test the private public getMifHeader() and private readMifHeader() functions 
        /// </summary>
        [Test]
        public void MifHeaderTest4()
        {
            string indexValue = (string)this.mif2.GetMifHeader()["version"];
            Assert.AreEqual(indexValue, "450");
        }

        /// <summary>
        /// test the private ReadMidData() and public getMidData() functions 
        /// </summary>
        [Test]
        public void MidDataTest1()
        {
            Assert.AreEqual(this.mif2.GetMidData().Columns.Count, 9);
        }

        /// <summary>
        /// Test the private ReadMidData() and public getMidData() functions 
        /// </summary>
        [Test]
        public void MidDataTest2()
        {
            int field_e_div_numberValue = (int)this.mif2.GetMidData().Rows[0][0];
            Assert.AreEqual(field_e_div_numberValue, 1);
        }

        /// <summary>
        /// test the private ReadMidData() and public getMidData() functions 
        /// </summary>
        [Test]
        public void MidDataTest3()
        {
            string elect_divValue = (string)this.mif2.GetMidData().Rows[0][1];
            Assert.AreEqual(elect_divValue, "Blair");
        }

        /// <summary>
        /// test the private ReadMidData() and public getMidData() functions 
        /// </summary>
        [Test]
        public void MidDataTest4()
        {
            int numccdsValue = (int)this.mif2.GetMidData().Rows[0][2];
            Assert.AreEqual(numccdsValue, 273);
        }

        /// <summary>
        /// test the private ReadMidData() and public getMidData() functions 
        /// </summary>
        [Test]
        public void MidDataTest5()
        {
            int actualValue = (int)this.mif2.GetMidData().Rows[0][3];
            Assert.AreEqual(actualValue, 87171);
        }

        /// <summary>
        /// test the private ReadMidData() and public getMidData() functions 
        /// </summary>
        [Test]
        public void MidDataTest6()
        {
            int projectedValue = (int)this.mif2.GetMidData().Rows[0][4];
            Assert.AreEqual(projectedValue, 92524);
        }

        /// <summary>
        /// test the private ReadMidData() and public getMidData() functions 
        /// </summary>
        [Test]
        public void MidDataTest7()
        {
            int total_PopulationValue = (int)this.mif2.GetMidData().Rows[0][5];
            Assert.AreEqual(total_PopulationValue, 87454);
        }

        /// <summary>
        /// test the private ReadMidData() and public getMidData() functions 
        /// </summary>
        [Test]
        public void MidDataTest8()
        {
            int fieldAo18Value = (int)this.mif2.GetMidData().Rows[0][6];
            Assert.AreEqual(fieldAo18Value, 87454);
        }

        /// <summary>
        /// test the private ReadMidData() and public getMidData() functions 
        /// </summary>
        [Test]
        public void MidDataTest9()
        {
            double area_SqKmValue = (double)this.mif2.GetMidData().Rows[0][7];
            Assert.AreEqual(area_SqKmValue, 14859.51);
        }

        /// <summary>
        /// test the private ReadMidData() and public getMidData() functions 
        /// </summary>
        [Test]
        public void MidDataTest10()
        {
            string sortnameValue = (string)this.mif2.GetMidData().Rows[0][8];
            Assert.AreEqual(sortnameValue, "Blair");
        }

        /// <summary>
        /// test the private ReadMidData() and public getMidData() functions 
        /// </summary>
        [Test]
        public void MidDataTest11()
        {
            string colName0 = (string)this.mif2.GetMidData().Columns[0].ColumnName;
            Assert.AreEqual(colName0, "E_div_number");
        }

        /// <summary>
        /// test the private ReadMidData() and public getMidData() functions 
        /// </summary>
        [Test]
        public void MidDataTest12()
        {
            string colName1 = (string)this.mif2.GetMidData().Columns[1].ColumnName;
            Assert.AreEqual(colName1, "Elect_div");
        }

        /// <summary>
        /// test the private ReadMidData() and public getMidData() functions 
        /// </summary>
        [Test]
        public void MidDataTest13()
        {
            string colName2 = (string)this.mif2.GetMidData().Columns[2].ColumnName;
            Assert.AreEqual(colName2, "Numccds");
        }

        /// <summary>
        /// test the private ReadMidData() and public getMidData() functions 
        /// </summary>
        [Test]
        public void MidDataTest14()
        {
            string colName3 = (string)this.mif2.GetMidData().Columns[3].ColumnName;
            Assert.AreEqual(colName3, "Actual");
        }

        /// <summary>
        /// test the private ReadMidData() and public getMidData() functions 
        /// </summary>
        [Test]
        public void MidDataTest15()
        {
            string colName4 = (string)this.mif2.GetMidData().Columns[4].ColumnName;
            Assert.AreEqual(colName4, "Projected");
        }

        /// <summary>
        /// test the private ReadMidData() and public getMidData() functions 
        /// </summary>
        [Test]
        public void MidDataTest16()
        {
            string colName5 = (string)this.mif2.GetMidData().Columns[5].ColumnName;
            Assert.AreEqual(colName5, "Total_Population");
        }

        /// <summary>
        /// test the private ReadMidData() and public getMidData() functions 
        /// </summary>
        [Test]
        public void MidDataTest17()
        {
            string colName6 = (string)this.mif2.GetMidData().Columns[6].ColumnName;
            Assert.AreEqual(colName6, "Australians_Over_18");
        }

        /// <summary>
        /// test the private ReadMidData() and public getMidData() functions 
        /// </summary>
        [Test]
        public void MidDataTest18()
        {
            string colName7 = (string)this.mif2.GetMidData().Columns[7].ColumnName;
            Assert.AreEqual(colName7, "Area_SqKm");
        }

        /// <summary>
        /// test the private ReadMidData() and public getMidData() functions 
        /// </summary>
        [Test]
        public void MidDataTest19()
        {
            string colName8 = (string)this.mif2.GetMidData().Columns[8].ColumnName;
            Assert.AreEqual(colName8, "Sortname");
        }
    }
}